﻿//---------------------------------------------------------------------
//Copyright (c) 2009, Pierre Milet
//All rights reserved.
//
//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 
//OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
//PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
//TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
//---------------------------------------------------------------------
using System;
using System.Xml;
using Microsoft.BizTalk.Component.Interop;
using Microsoft.Samples.BizTalk.Adapter.Common;

namespace BizMock.Adapter.Runtime
{
    /// <summary>
    /// Summary description for BizMockReceiveProperties.
    /// </summary>
    internal class BizMockReceiveProperties : ConfigProperties
    {
		// Handler members...
        private static int batchSize = 50;

		// Endpoint members...
        private bool isTwoWay;
		private int timeout = 90; // in seconds

		public BizMockReceiveProperties(string url)
		{
		}

		public static void HandlerConfiguration(XmlDocument configDOM)
		{
			// Handler properties

		}

		public static void HandlerConfiguration(IPropertyBag config, IPropertyBag bizTalkConfig)
		{
			// Handler properties
			XmlDocument configDOM = ExtractConfigDomImpl(config, true);

		}

		public void LocationConfiguration(IPropertyBag config, IPropertyBag bizTalkConfig)
		{
			XmlDocument configDOM = ExtractConfigDomImpl(config, true);


			// The property "TwoWayReceivePort" in the BizTalk Config
			// property bag indicates whether the port is one or two way...
			object obj = null;
            bizTalkConfig.Read("TwoWayReceivePort", out obj, 0);

			if (null != obj)
				this.isTwoWay = (bool)obj;
            if (Extract(configDOM, "/Config/timeout", "90") != string.Empty )
                timeout = int.Parse( Extract(configDOM, "/Config/timeout", "90") );

		}
			
		//Receive handler properties
		public static int BatchSize	{ get { return BizMockReceiveProperties.batchSize; }	}

		//Receive location properties
        public bool IsTwoWay { get { return this.isTwoWay; } }
		
		public int Timeout { get { return timeout; } } // in seconds
    }
}
